home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 215_01.zip / BBSCMISC.C < prev    next >
Text File  |  1980-01-01  |  5KB  |  279 lines

  1. /*
  2.     bbscmisc.c
  3.  
  4.     Support routines used by BBSc.c.
  5.                 Mike Kelly
  6.  
  7.     06/12/83 v1.0    written
  8.     07/07/83 v1.0    updated
  9. */
  10.  
  11. #include "bdscio.h"
  12. #include "bbscdef.h"
  13.  
  14.  
  15. #define LASTDATE  " 07/07/83 "
  16.  
  17. #define PGMNAME "BBSCMISC "
  18. #define VERSION " 1.0 "
  19.  
  20.  
  21. strfill(buf,fillchar,length)    /* fill a string with fillchar */
  22. char    *buf;            /*  for length -1 */
  23. int    fillchar,
  24.     length;
  25. {
  26.     while(--length)        /* really is length -1 */
  27.     {
  28.         *buf++ = fillchar;
  29.     }
  30.     *buf++ = '\0';        /* need room for this */
  31. }
  32.  
  33.  
  34. prthex(string)        /* printf a string showing each char and it's */
  35. char    *string;    /*  hex value  ie.  A<41> */
  36. {
  37.     char    byte,
  38.         byte1;
  39.  
  40.     while (*string)
  41.     {
  42.         byte = (*string++);
  43.         byte1 = byte;
  44.         if (byte < 0x20)
  45.         {
  46.             byte1 = ' ';
  47.         }
  48.         printf("%c<%02x>",byte1,byte);
  49.     }
  50.     printf("\n");
  51. }
  52.  
  53. prtihex(integer)    /* like prthex, but for integers */
  54. int    integer;
  55. {
  56.  
  57.     printf("%09d<%04x>",integer,integer);
  58.     printf("\n");
  59. }
  60.  
  61. substr(from,to,start,length)    /* moves chars from "from" to "to" */
  62. char    *from,            /*  starting at "start" for */
  63.     *to;            /*  "length" number of chars */
  64. int    start,        /* for beginning of string use 1, not 0 */
  65.     length;
  66. {
  67.     int    cnt;
  68.  
  69.     cnt = 0;
  70.  
  71.     while(--start)        /* adjust sending field pointer */
  72.     {
  73.         from++;        
  74.     }
  75.  
  76.     while((cnt < length) && (*to++ = *from++))    /* do the moving */
  77.     {
  78.         cnt++;        
  79.     }
  80.     
  81.     *to = '\0';
  82.  
  83. }
  84.  
  85. putd(byte)    /* do direct console output */
  86. char    byte;
  87. {
  88.     bdos(6,byte);
  89. }    
  90. /*    end of function        */
  91.  
  92.  
  93. savepos()        /* save current cursor position */
  94. {
  95.     putch(ESC);
  96.     putch('j');
  97. }
  98. /*    end of function        */
  99.  
  100. retpos()        /* returns cursor to previously saved position */
  101. {
  102.     putch(ESC);
  103.     putch('k');
  104. }
  105. /*    end of function        */
  106.  
  107. to(linex,coly)        /* positions cursor to line and column given */
  108. int    linex,
  109.     coly;
  110. {
  111.     if (linex == 25)
  112.     {
  113.         on25();
  114.     }
  115.     putch(ESC);
  116.     putch('Y');
  117.     putch(linex+31);
  118.     putch(coly+31);
  119. }
  120. /*    end of function        */
  121.  
  122. on25()            /* enable line 25 */
  123. {
  124.     putch(ESC);
  125.     putch('x');
  126.     putch('1');
  127. }
  128. /*    end of function        */
  129.  
  130. off25()            /* disables line 25 */
  131. {
  132.     putch(ESC);
  133.     putch('y');
  134.     putch('1');
  135. }
  136. /*    end of function        */
  137.  
  138. puts(s)            /* this function replaces the one in the */
  139. char    *s;        /*   bds c library */
  140. {
  141.     while (*s)
  142.     {
  143.         putch(*s++);    /* putch instead of putchar */
  144.     }            /*  don't want to look for keyboard hit */
  145. }                /*  during put of a char */
  146. /*     end of function        */
  147.  
  148.  
  149. getline(buf,max)    /* get a line of input max. chars long */
  150. int    max;
  151. char    *buf;
  152. {
  153.     int    cnt,
  154.         byte;
  155.     char    bytex;
  156.  
  157.     cnt = 0;
  158. #ifdef DEBUG
  159.     if (debug)
  160.     {
  161.         printf("in getline\n");
  162.         printf("  max=%05d  cnt=%05d\n",max,cnt);
  163.     }
  164. #endif
  165.     byte = FALSE;
  166.     while (++cnt <= max && byte != '\r' && byte != '\n')
  167.     {
  168.         while((byte = getd()) < ' ' || byte > '}')
  169.         {
  170.             if (byte == '\r')
  171.             {
  172.                 *buf++ = byte;
  173.                 byte = '\n';
  174.                 break;
  175.             }
  176.         }
  177.         *buf++ = byte;
  178.         putd(byte);        /* echo good chars only */
  179.     }
  180.  
  181.     if (cnt >= max)
  182.     {
  183.         byte = '\r';        /* <cr> */
  184.         *buf++ = byte;
  185.         putd(byte);
  186.  
  187.         byte = '\n';        /* <lf> */
  188.         *buf++ = byte;
  189.         putd(byte);
  190.     }
  191.  
  192.     *buf++    = '\0';            /* tag \0 on end */
  193. #ifdef DEBUG
  194.     if (debug)
  195.     {
  196.         printf("  cnt=%05d\n",cnt);
  197.     }
  198. #endif
  199. }
  200. /*    end of function        */
  201.  
  202. getd()        /* do direct console input - returns when char present */
  203. {
  204.     int    bytei;
  205.  
  206.     while ((bytei = bdos(6,0xff)) == 0x00)
  207.     {
  208.         ;
  209.     }
  210. #ifdef DEBUG
  211.     if (debug)
  212.     {
  213.         printf("<%02x>",bytei);
  214.     }
  215. #endif
  216.     return(bytei);
  217. }
  218. /*    end of function        */
  219.  
  220. /* putd(byte)    /* do direct console output */
  221. char    byte;
  222. {
  223.     bdos(6,byte);
  224. /*    if (debug)
  225.     {
  226.         printf("<%02x>",byte);
  227.     }
  228. */
  229. }    
  230. /*    end of function        */
  231. */
  232.  
  233.  
  234. fldcpy(to,from)        /* just like strcpy, except puts \0 at end */
  235. char    *to,        /*   of to string */
  236.     *from;
  237. {
  238.     while(*to++ = *from++);
  239.     *++to = '\0';        /* put \0 in to string */
  240. }
  241. /*    end of function    */
  242.  
  243.  
  244. clear()        /*    clear screen    */
  245. {
  246.     putch(ESC);
  247.     putch(CLEAR);
  248. }
  249. /*    end of function        */
  250.  
  251. char putst(string)
  252. char *string; 
  253. {
  254. /*    printf("\nstring=");
  255. */
  256.     while(*string)
  257.     {
  258.         putchar(*string++);
  259.     }
  260.     putchar("\n");
  261. }
  262. /*    end of function        */
  263.  
  264.  
  265. itoa(str,n)        /* taken from float.c */
  266. char *str;
  267. {
  268.     char *sptr;
  269.     sptr = str;
  270.     if (n<0) { *sptr++ = '-'; n = -n; }
  271.     _uspr(&sptr, n, 10);
  272.     *sptr = '\0';
  273.     return str;
  274. }
  275. /*    end of function        */
  276.  
  277.  
  278. /*    end of program      */
  279.